package com.csd.controller;

import com.csd.common.JsonBean;
import com.csd.dto.ActionResult;
import com.csd.pojo.SysCity;
import com.csd.service.CarCityService;
import com.csd.utils.JsonUtils;
import com.csd.vo.Vcity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ Author :lihainan
 * @ ClassNmae :CarCityController
 * @ Description :TODO
 * @ Date :2020/12/22
 * @ Version 1.0
 */
@RestController
public class CarCityController {

    @Autowired
    private CarCityService carCityService;

    @RequestMapping("/CityList")
    @ResponseBody
    public JsonBean selectAll(Integer pid){
        JsonBean bean = null;

        try {
            List<SysCity> list = carCityService.selectCitiesByPid(pid);
            bean = JsonUtils.createJsonBean(1,list);
        } catch (Exception e) {
            bean = JsonUtils.createJsonBean(0,e.getMessage());
        }
        return bean ;
    }

    @RequestMapping("/all")
    @ResponseBody
    public JsonBean selectAllInfo(){
        JsonBean bean = null;

        try {
            List<SysCity> list = carCityService.selectAllInfo();
            bean = JsonUtils.createJsonBean(1,list);
        } catch (Exception e) {
            bean = JsonUtils.createJsonBean(0,e.getMessage());
        }
        return bean ;
    }

    @RequestMapping("/citys")
    @ResponseBody
    public JsonBean selectCitys(Integer getid, Integer backid){
        JsonBean bean = null;

        try {
            Vcity vcity = carCityService.selectCitys(getid, backid);
            bean = JsonUtils.createJsonBean(1,vcity);
        } catch (Exception e) {
            bean = JsonUtils.createJsonBean(0,e.getMessage());
        }
        return bean ;
    }

}
